package com.gcxy.controller;


import com.gcxy.core.PageVO;
import com.gcxy.core.R;
import com.gcxy.dto.weekly.UpdateWeeklyDTO;
import com.gcxy.dto.student.ScheduledTasksDTO;

import com.gcxy.dto.weekly.WeeklyPageDTO;
import com.gcxy.dto.weekly.WeeklyReviewDTO;
import com.gcxy.service.WeeklyService;
import com.gcxy.vo.weekly.WeeklyAppraiseVO;
import com.gcxy.vo.weekly.WeeklyPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 周报信息 前端控制器
 * </p>
 *
 * @author Huang先森
 * @since 2024-07-22
 */
@Api(tags = "周报管理")
@RestController
@RequestMapping("/weekly")
public class WeeklyController {

    @Autowired
    private WeeklyService weeklyService;

    @ApiOperation("定时生成周报")
    @PostMapping("/addWeeklyScheduled")
    public R<?> addWeeklyScheduled(@RequestBody @Validated ScheduledTasksDTO scheduledTasksDTO) {
        return weeklyService.addWeeklyScheduled(scheduledTasksDTO);
    }

    @ApiOperation("手动执行定时任务")
    @GetMapping("/manualExecutionScheduled")
    public R<?> manualExecutionScheduled() {
        weeklyService.manualExecutionScheduled();
        return R.Success();
    }

    @ApiOperation("修改周报")
    @PostMapping("/updateWeekly")
    public R<?> updateWeekly(@RequestBody @Validated UpdateWeeklyDTO updateWeeklyDTO) {
        return weeklyService.updateWeekly(updateWeeklyDTO);
    }

    @ApiOperation(value = "周报评阅")
    @PostMapping(value = "/weeklyReview")
    public R<?> weeklyReview(@RequestBody @Validated WeeklyReviewDTO weeklyReviewDTO) {
        return weeklyService.weeklyReview(weeklyReviewDTO);
    }

    @ApiOperation(value = "周报分页查询")
    @PostMapping(value = "/getWeeklyByPage")
    public R<PageVO<WeeklyPageVO>> getWeeklyByPage(@RequestBody @Validated WeeklyPageDTO weeklyPageDTO) {
        return weeklyService.getWeeklyByPage(weeklyPageDTO);
    }

    @ApiOperation(value = "根据id获取周报信息")
    @GetMapping(value = "/getWeeklyById")
    public R<WeeklyAppraiseVO> getWeeklyById(@RequestParam("id") @NotNull(message = "周报id不能为空") Integer weeklyId) {
        return weeklyService.getWeeklyById(weeklyId);
    }

    @ApiOperation(value = "获取周数信息")
    @GetMapping(value = "/getWeekNum")
    public R<List<Integer>> getWeekNum(@RequestParam("semesterId") @NotNull(message = "学期id不能为空") Integer semesterId) {
        return weeklyService.getWeekNum(semesterId);
    }
}

